
/*-----------------------------------------------------
--------------------------------------------------------
Exploring Household Heterogeneities 
of the Deaton-Paxson Puzzle: 
Evidence for Argentina
--------------------------------------------------------
Echeverria (a, b) and Molina (c, d), 2021
--------------------------------------------------------
a CONICET and University of Mar del Plata, Argentina
b Department of Economic Analysis, University of Zaragoza, Spain 
c Department of Economic Analysis, University of Zaragoza, Spain
d Institute of Labor Economics, ZA, Germany
--------------------------------------------------------
-----------------------------------------------------*/


* DIRECTORY
cd "C:\..."
use "Data ENGH.dta", clear



* TABLE 1:  
summ w_f ln_totexp ln_pce ln_pci
summ hh1a-hh5a
summ hh2a1c-hh2a5c

summ hhsize n_adults ratio_a1865 ratio_a65
tab n_children if n_children!=0			  
summ n_children ratio_c05 ratio_c612 ratio_c1217 if n_children!=0

summ  i.region i.trimestre jefe_edad jefe_sexo ///
			  working_a  jefe_educbaja jefe_educmedia
			  

*  GRAPHS
lpoly w_f ln_pce if hhsize==1, degree(1) noscatter acolor(green) ///
			addplot (lpoly  w_f ln_pce if hhsize==2, degree(1) lcolor(red) lpattern (dash) ///
			|| lpoly w_f ln_pce if hhsize==3, degree(1) lcolor(blue) lpattern (dash) ///
			|| lpoly w_f ln_pce if hhsize>3, degree(1) lcolor(orange) lpattern (dash)) ///
			ytitle("food share") subtitle("Panel (A): all households") ///
			legend(label(1 "1 member") ///
			label(2 "2 members") ///
			label(3 "3 members")label(4 "+ 3 members")) 

lpoly w_f ln_pce if hh1a==1, degree(1) noscatter acolor(green) ///
			addplot (lpoly  w_f ln_pce if hh2a==1, degree(1) lcolor(red) lpattern (dash) ///
			|| lpoly w_f ln_pce if hh3a==1, degree(1) lcolor(blue) lpattern (dash) ///
			|| lpoly w_f ln_pce if (hh4a==1), degree(1) lcolor(orange) lpattern (dash)) ///
			ytitle("food share") subtitle("Panel (B): adults (without children)") ///
			legend(label(1 "1 adult") ///
			label(2 "2 adults") ///
			label(3 "3 adults")label(4 "4 adults")) 

lpoly w_f ln_pce if hh2a==1, degree(1) noscatter acolor(green) ///
			addplot (lpoly  w_f ln_pce if hh2a1c==1, degree(1) lcolor(red) lpattern (dash) ///
			|| lpoly w_f ln_pce if hh2a2c==1, degree(1) lcolor(blue)  lpattern (dash) ///
			|| lpoly w_f ln_pce if (hh2a3c==1 | hh2a4c==1 | hh2a5c==1), degree(1) lcolor(orange) lpattern (dash)) ///
		ytitle("food share") subtitle("Panel (C): 2 adults with and without children") yscale(r(0.2 0.5)) ///
			legend(label(1 "2 adults without children") ///
			label(2 "2 adults and 1 child") ///
			label(3 "2 adults and 2 children")label(4 "2 adults and + 3 children")) 


* TABLE 2

// OLS
reg w_f ln_pce ln_hhsize, robust

reg w_f ln_pce ln_hhsize ///
		      ratio_c05 ratio_c612 ratio_c1217 ratio_a65 ///
			  i.region i.trimestre jefe_edad jefe_sexo working_a ///
			  jefe_educbaja jefe_educmedia, robust

// IV 
ivregress 2sls w_f ln_hhsize (ln_pce = ln_pci)
estat firststage

ivregress 2sls w_f ln_hhsize ///
								  ratio_c05 ratio_c612 ratio_c1217 ratio_a65 ///
								   i.region i.trimestre jefe_edad jefe_sexo working_a ///
								   jefe_educbaja jefe_educmedia  (ln_pce = ln_pci)
estat firststage


* TABLE 3									
ivregress 2sls w_f ln_hhsize ///
								   ratio_a65 ///
								   i.region i.trimestre jefe_edad jefe_sexo working_a ///
								   jefe_educbaja jefe_educmedia  (ln_pce = ln_pci) ///
									 if (n_children==0)
  
ivregress 2sls w_f ln_hhsize ///
								   ratio_a65 ///
								   i.region i.trimestre jefe_edad jefe_sexo working_a ///
								   jefe_educbaja jefe_educmedia  (ln_pce = ln_pci) ///
								  if (hh1a==1 | hh2a==1), robust

ivregress 2sls w_f ln_hhsize ///
								   ratio_a65 ///
								   i.region i.trimestre jefe_edad jefe_sexo working_a ///
								   jefe_educbaja jefe_educmedia  (ln_pce = ln_pci) ///
								  if (hh2a==1 | hh3a==1), robust

ivregress 2sls w_f ln_hhsize ///
								   ratio_a65 ///
								   i.region i.trimestre jefe_edad jefe_sexo working_a ///
								   jefe_educbaja jefe_educmedia  (ln_pce = ln_pci) ///
								  if (hh3a==1  | hh4a==1  | hh5a==1)


* PANEL B
ivregress 2sls w_f ln_hhsize ///
								  ratio_c05 ratio_c612 ratio_c1217 ratio_a65 ///
								   i.region i.trimestre jefe_edad jefe_sexo working_a ///
								   jefe_educbaja jefe_educmedia  (ln_pce = ln_pci) ///
								   if (hh2a==1 | hh2a1c==1  | hh2a2c==1 | hh2a3c==1 | hh2a4c==1 | hh2a5c==1) 

ivregress 2sls w_f ln_hhsize ///
								  ratio_c05 ratio_c612 ratio_c1217 ratio_a65 ///
								   i.region i.trimestre jefe_edad jefe_sexo working_a ///
								   jefe_educbaja jefe_educmedia  (ln_pce = ln_pci) ///
								   if (hh2a==1 | hh2a1c==1) 

ivregress 2sls w_f ln_hhsize ///
								  ratio_c05 ratio_c612 ratio_c1217 ratio_a65 ///
								   i.region i.trimestre jefe_edad jefe_sexo working_a ///
								   jefe_educbaja jefe_educmedia  (ln_pce = ln_pci) ///
								   if (hh2a1c==1 | hh2a2c==1) 

ivregress 2sls w_f ln_hhsize ///
								  ratio_c05 ratio_c612 ratio_c1217 ratio_a65 ///
								   i.region i.trimestre jefe_edad jefe_sexo working_a ///
								   jefe_educbaja jefe_educmedia  (ln_pce = ln_pci) ///
								   if (hh2a2c==1 | hh2a3c==1  | hh2a4c==1 | hh2a5c==1) 

* TABLE 4																		   						  
forvalues j = 1/5 {

		ivregress 2sls w_f ln_hhsize ///
								 ratio_c05 ratio_c612 ratio_c1217 ///
								 i.region i.trimestre jefe_edad jefe_sexo working_a ///
								 jefe_educbaja jefe_educmedia  (ln_pce = ln_pci) if quintile_pci == `j'
}	 
			
					
* TABLE 5
regress ln_pce ln_pci ln_hhsize ///
			  ratio_c05 ratio_c612 ratio_c1217 ratio_a65 ///
			  i.region i.trimestre jefe_edad jefe_sexo working_a ///
			  jefe_educbaja jefe_educmedia
predict double ln_pce_hat, xb

bootstrap _b, reps(200): qreg w_f ln_pce_hat ln_hhsize ///
																ratio_c05 ratio_c612 ratio_c1217 ratio_a65 ///
																i.region i.trimestre jefe_edad jefe_sexo working_a ///
																jefe_educbaja jefe_educmedia, q(10)
predict y_10

bootstrap _b, reps(200): qreg w_f ln_pce_hat ln_hhsize ///
																ratio_c05 ratio_c612 ratio_c1217 ratio_a65 ///
																i.region i.trimestre jefe_edad jefe_sexo working_a ///
																jefe_educbaja jefe_educmedia, q(15)
predict y_15

bootstrap _b, reps(200): qreg w_f ln_pce_hat ln_hhsize ///
																ratio_c05 ratio_c612 ratio_c1217 ratio_a65 ///
																i.region i.trimestre jefe_edad jefe_sexo working_a ///
																jefe_educbaja jefe_educmedia, q(40)
predict y_40

bootstrap _b, reps(200): qreg w_f ln_pce_hat ln_hhsize ///
																ratio_c05 ratio_c612 ratio_c1217 ratio_a65 ///
																i.region i.trimestre jefe_edad jefe_sexo working_a ///
																jefe_educbaja jefe_educmedia, q(60)
predict y_60

bootstrap _b, reps(200): qreg w_f ln_pce_hat ln_hhsize ///
																ratio_c05 ratio_c612 ratio_c1217 ratio_a65 ///
																i.region i.trimestre jefe_edad jefe_sexo working_a ///
																jefe_educbaja jefe_educmedia, q(85)
predict y_85

bootstrap _b, reps(200): qreg w_f ln_pce_hat ln_hhsize ///
																ratio_c05 ratio_c612 ratio_c1217 ratio_a65 ///
																i.region i.trimestre jefe_edad jefe_sexo working_a ///
																jefe_educbaja jefe_educmedia, q(90)
predict y_90

// Figure 1.A.
twoway (lfit y_10 ln_pce) (lfit y_15 ln_pce) ///
				(lfit y_40 ln_pce) (lfit y_60 ln_pce) (lfit y_85 ln_pce) ///
				(lfit y_90 ln_pce), legend(label(1 "Q (0.10)") ///
				label(2 "Q (0.15)") label(3 "Q (0.40)") label(4 "Q (0.60)") ///
				label(5 "Q (0.85)") label(6 "Q (0.90)")) ///
				xtitle(log of per capita expenditure) ytitle(food share) subtitle("all households")

// Figure 2				
twoway 	(lfit y_10 ln_pce if hhsize==1) (lfit y_90 ln_pce if hhsize==1) ///
				(lfit y_10 ln_pce if hhsize==2, lpattern(dash)) (lfit y_90 ln_pce if hhsize==2, lpattern(dash)) ///
				(lfit y_10 ln_pce if hhsize==3, lpattern(dash)) (lfit y_90 ln_pce if hhsize==3, lpattern(dash)), ///
				legend(label(1 "Q 10: 1 member") label(2 "Q 90: 1 member") ///
				label(3 "Q 10: 2 members") label(4 "Q 90: 2 members") ///
				label(5 "Q 10: 3 members") label(6 "Q 90: 3 members")) ///
				xtitle(log of per capita expenditure) ytitle(food share) subtitle("all households")

sqreg w_f ln_pce_hat ln_hhsize ///
										ratio_c05 ratio_c612 ratio_c1217 ratio_a65 ///
										i.region i.trimestre jefe_edad jefe_sexo working_a ///
										jefe_educbaja jefe_educmedia, q(10 15 40 60 85 90) reps(200)

drop ln_pce_hat
drop y_*

*  TABLE 6			
regress ln_pce ln_pci ln_hhsize ///
			  ratio_a65 ///
			  i.region i.trimestre jefe_edad jefe_sexo working_a ///
			  jefe_educbaja jefe_educmedia  if n_children==0
			  
predict double ln_pce_hat, xb

bootstrap _b, reps(200): qreg w_f ln_pce_hat ln_hhsize ///
																ratio_a65 ///
																i.region i.trimestre jefe_edad jefe_sexo working_a ///
																jefe_educbaja jefe_educmedia ///
																if n_children==0, q(10)

bootstrap _b, reps(200): qreg w_f ln_pce_hat ln_hhsize ///
																ratio_a65 ///
																i.region i.trimestre jefe_edad jefe_sexo working_a ///
																jefe_educbaja jefe_educmedia ///
																if n_children==0, q(15)

bootstrap _b, reps(200): qreg w_f ln_pce_hat ln_hhsize ///
																ratio_a65 ///
																i.region i.trimestre jefe_edad jefe_sexo working_a ///
																jefe_educbaja jefe_educmedia ///
																if n_children==0, q(85)

bootstrap _b, reps(200): qreg w_f ln_pce_hat ln_hhsize ///
																ratio_a65 ///
																i.region i.trimestre jefe_edad jefe_sexo working_a ///
																jefe_educbaja jefe_educmedia ///
																if n_children==0, q(90)

drop ln_pce_hat


* IV QREG

regress ln_pce ln_pci ln_hhsize ///
			  ratio_c05 ratio_c612 ratio_c1217 ratio_a65 ///
			  i.region i.trimestre jefe_edad jefe_sexo working_a ///
			  jefe_educbaja jefe_educmedia ///
			  if (hh2a==1 | hh2a1c==1  | hh2a2c==1 | hh2a3c==1 | hh2a4c==1 | hh2a5c==1)		  
predict double ln_pce_hat, xb

bootstrap _b, reps(200): qreg w_f ln_pce_hat ln_hhsize ///
																ratio_c05 ratio_c612 ratio_c1217 ratio_a65 ///
																i.region i.trimestre jefe_edad jefe_sexo working_a ///
																jefe_educbaja jefe_educmedia ///
																if (hh2a==1 | hh2a1c==1  | hh2a2c==1 | hh2a3c==1 | hh2a4c==1 | hh2a5c==1), q(10)

bootstrap _b, reps(200): qreg w_f ln_pce_hat ln_hhsize ///
																ratio_c05 ratio_c612 ratio_c1217 ratio_a65 ///
																i.region i.trimestre jefe_edad jefe_sexo working_a ///
																jefe_educbaja jefe_educmedia ///
																if (hh2a==1 | hh2a1c==1  | hh2a2c==1 | hh2a3c==1 | hh2a4c==1 | hh2a5c==1), q(15)

bootstrap _b, reps(200): qreg w_f ln_pce_hat ln_hhsize ///
																ratio_c05 ratio_c612 ratio_c1217 ratio_a65 ///
																i.region i.trimestre jefe_edad jefe_sexo working_a ///
																jefe_educbaja jefe_educmedia ///
																if (hh2a==1 | hh2a1c==1  | hh2a2c==1 | hh2a3c==1 | hh2a4c==1 | hh2a5c==1), q(85)

bootstrap _b, reps(200): qreg w_f ln_pce_hat ln_hhsize ///
																ratio_c05 ratio_c612 ratio_c1217 ratio_a65 ///
																i.region i.trimestre jefe_edad jefe_sexo working_a ///
																jefe_educbaja jefe_educmedia ///
																if (hh2a==1 | hh2a1c==1  | hh2a2c==1 | hh2a3c==1 | hh2a4c==1 | hh2a5c==1), q(90)

drop ln_pce_hat


* end




